package mn.idax.exchange.otc.util.function;

import mn.idax.exchange.common.BizLoggerUtil;
import mn.idax.exchange.common.OrderProcessLog;
import mn.idax.exchange.otc.exception.IdaxException;

import java.util.function.Consumer;

/**
 * @Auther: dison
 * @Date: 2018/10/12 14:45
 * @Description:
 */
public class OrderProcessLogFunction {

    /**
     *
     * 功能描述:
     *      日志埋点实现
     * @param:
     * @return:
     * @auther: dison
     * @date: 2018/10/12 16:24
     */
    public static void logOrderProcess(Consumer consumer ,Class<?> clazz , String mark){
        /**开始时间**/
        long start = System.currentTimeMillis();
        try{
            consumer.accept(null);
        }catch (IdaxException e){
            throw e;
        }finally {
            /**记录日志**/
            OrderProcessLog processLog = new OrderProcessLog();
            processLog.setStartTime(start);
            processLog.setElapsedTime(System.currentTimeMillis() - start);
            processLog.setMark(mark);

            BizLoggerUtil.logOrderProcess(processLog);
        }
    }
}
